<?php

namespace App\Repositories\Album;

use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Models\Album\AlbumText;
use Prettus\Repository\Traits\CacheableRepository;

/**
 * Class AlbumTextRepositoryEloquent.
 *
 * @package namespace App\Repositories\Album;
 */
class AlbumTextRepositoryEloquent extends BaseRepository implements AlbumTextRepository
{

    use CacheableRepository;

    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return AlbumText::class;
    }

    

    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }

    /**
     * @author Jerry
     * @param int $id
     * @return mixed
     */
    public function findAlbumTextByTemplateId(int $id)
    {
        $where = [
            'template_id'   =>  $id,
        ];

        $expiresAt = Carbon::now()->addDay(1);
        return Cache::remember("album:text{$id}", $expiresAt, function () use ($where) {
            return $this->findWhere($where)->first();
        });
    }
    
}
